package com.lianzai.shop.service.impl;

import com.lianzai.shop.dao.ShopDao;
import com.lianzai.shop.dao.ShopTicketDao;
import com.lianzai.shop.model.Shop;
import com.lianzai.shop.model.ShopTicket;
import com.lianzai.shop.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ShopServiceImpl implements ShopService {
	@Autowired
	private ShopDao shopDao;

	@Autowired
	private ShopTicketDao shopTicketDao;

	@Override
	public List<Shop> list(Map<String, Object> map){
		List<Shop> shopList = shopDao.list(map);
		for(Shop shop:shopList){//查询每一个商户的停车券信息
			List<ShopTicket> shopTicketList = shopTicketDao.listByUserId(shop.getId());
			String shopTicketMsg = "";
			for(ShopTicket shopTicket:shopTicketList){
				String ticketName = shopTicket.getTicketName();
				Long ticketBuyedNum = shopTicket.getTicketBuyedNum();
				Long ticketRemainNum = shopTicket.getTicketRemainNum();
				Integer status = shopTicket.getStatus();
				String statusMsg = "不可用";
				if(status == 1){
					statusMsg = "可用";
				}
				if("".equals(shopTicketMsg)){
					shopTicketMsg = "<span>券名：</span><span style='color:Red;font-size:16px;font-weight:bold'>"+ticketName+"</span><span>&nbsp;，购买：</span><span style='color:Red;font-size:16px;font-weight:bold'>"+ticketBuyedNum+"</span><span>&nbsp;张</span><span>&nbsp;，剩余：</span><span style='color:Red;font-size:16px;font-weight:bold'>"+ticketRemainNum+"</span><span>&nbsp;张</span>";
				}else{
					shopTicketMsg = shopTicketMsg + "<div style='border-top:0.5px #999 solid;'><span>券名：</span><span style='color:Red;font-size:16px;font-weight:bold'>"+ticketName+"</span><span>&nbsp;，购买：</span><span style='color:Red;font-size:16px;font-weight:bold'>"+ticketBuyedNum+"</span><span>&nbsp;张</span><span>&nbsp;，剩余：</span><span style='color:Red;font-size:16px;font-weight:bold'>"+ticketRemainNum+"</span><span>&nbsp;张</span></div>";
				}
			}
			if(!"".equals(shopTicketMsg)){
				shop.setShopTicketMsg(shopTicketMsg);
			}
		}
		return shopList;
	}

	@Override
	public int count(Map<String, Object> map){
		return shopDao.count(map);
	}

	@Override
	public int remove(Long id){
		return shopDao.remove(id);
	}

	@Override
	public int removeLicense(Long id){
		return shopDao.removeLicense(id);
	}

	@Override
	public List<Map<String, Object>> queryTicektShopUsedList(Map<String, Object> map){
		return shopDao.queryTicektShopUsedList(map);
	}

	@Override
	public int save(Shop shop){
		return shopDao.save(shop);
	}

	@Override
	public int update(Shop shop){
		return shopDao.update(shop);
	}

	@Override
	public int updateLicense(Shop shop){
		return shopDao.updateLicense(shop);
	}

	@Override
	public int insertLicense(Shop shop){
		return shopDao.insertLicense(shop);
	}

	@Override
	public int pass(Shop shop){
		return shopDao.pass(shop);
	}

	@Override
	public Shop get(Long id){
		return shopDao.get(id);
	}

	@Override
	public List<Map<String, String>> queryIndustryList(){
		return shopDao.queryIndustryList();
	};
}
